package com.zhang.zhangapp.view.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.zhang.zhangapp.R;
import com.zhang.zhangapp.view.BaseAppCompatActivityActivity;
import com.zhang.zhangapp.view.adapter.BankTypeAdapter;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ContentView(R.layout.activity_select_bank_type)
public class SelectBankTypeActivity extends BaseAppCompatActivityActivity {
    private final static String types = "001,中国银行;002,中国建行银行;003,中国农业银行;004,中国工商银行;005,招商银行;006,中国光大银行;007,兴业银行;008,民生银行;009,上海浦东发展银行;010,交通银行;011,中国邮政储蓄银行;012,其他";
    @ViewInject(R.id.select_bank_type_listview)
    ListView listView;
    @ViewInject(R.id.action_bar_title)
    TextView titleText;

    BankTypeAdapter adapter;

    List<Map<String, String>> typeList = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        initTypeList();
        initListView();
    }

    private void initTypeList() {
        String[] typeArr = types.split(";");
        for (String str : typeArr) {
            String[] arr = str.split(",");
            Map<String, String> map = new HashMap<>();
            map.put("code", arr[0]);
            map.put("name", arr[1]);
            typeList.add(map);
        }
    }

    private void initListView() {
        adapter = new BankTypeAdapter(this, typeList);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                SelectBankTypeActivity.this.getIntent().putExtra("type", typeList.get(i).get("code"));
                SelectBankTypeActivity.this.getIntent().putExtra("name", typeList.get(i).get("name"));
                SelectBankTypeActivity.this.setResult(SelectBankTypeActivity.this.RESULT_OK, SelectBankTypeActivity.this.getIntent());
                SelectBankTypeActivity.this.finish();
            }
        });
    }
}
